<template>
  <div class="professionBaseInfoFix">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>基础信息管理</el-breadcrumb-item>
      <el-breadcrumb-item>修改专业基本信息</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :model="updateProfessionForm" :rules="updateProfessionRules" ref="updateProfessionForm" label-width="100px"
             class="demo-ruleForm fixed-form">
      <el-form-item label="专业代码" prop="majorId">
        <el-input v-model="updateProfessionForm.majorId"></el-input>
      </el-form-item>
      <el-form-item label="学院编号" prop="collegeId">
        <el-input v-model="updateProfessionForm.collegeId"></el-input>
      </el-form-item>
      <el-form-item label="专业名称" prop="majorName">
        <el-input v-model="updateProfessionForm.majorName"></el-input>
      </el-form-item>
      <el-form-item label="专业简称" prop="majorShortName">
        <el-input v-model="updateProfessionForm.majorShortName"></el-input>
      </el-form-item>
      <el-form-item label="学科门类" prop="majorSort">
        <el-select v-model="updateProfessionForm.majorSort" placeholder="请选择学科门类" class="max-width">
          <el-option label="理工科" value="理工科"></el-option>
          <el-option label="文史科" value="文史科"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="专业负责人" prop="majorManager">
        <el-input v-model="updateProfessionForm.majorManager"></el-input>
      </el-form-item>
      <el-form-item label="教研室主任" prop="teachingDirector">
        <el-input v-model="updateProfessionForm.teachingDirector"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('updateProfessionForm')">立即创建</el-button>
        <el-button @click="resetForm('updateProfessionForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<style>
</style>
<script>
  export default{
    name: 'professionBaseInfoFix',
    data(){
      return {
        getContentURL: '',
        updateInfoURl: '',
        oldMajorId: '',
        updateProfessionForm: {
          majorId: '',
          collegeId: '',
          majorName: '',
          majorShortName: '',
          majorSort: '',
          majorManager: '',
          teachingDirector: ''
        },
        updateProfessionRules: {
          majorId: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          collegeId: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorName: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorShortName: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorSort: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorManager: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          teachingDirector: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ]
        }
      }
    },
    components: {},
    mounted: function () {
      this.$nextTick(function () {
        //保存进来时候的id
        this.oldMajorId = this.$route.params.majorId;
        //表单内的id赋值
        this.updateProfessionForm.majorId = this.$route.params.majorId;
        //获取id对应的内容
        this.getIDRes(this.updateProfessionForm.majorId);
      })
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            //上传更新内容
            this.$http.post(this.$until.url + '/majorBaseInfo/updateMajor', this.updateProfessionForm,
              {
                params: {
                  oldMajorId: this.oldMajorId
                },
                emulateJSON: true
              }).then(response => {
              //success
              this.$message({
                message: response.body.message,
                type: 'success'
              });
              //  -> 专业基本信息
              this.$router.replace({path: '/ProfessionBaseInfo'});
            }, response => {
              console.log('文件获取失败');
            });


          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      //重置表单
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      //获取 id 对应的值
      getIDRes: function (elementID) {
        this.$http.post(this.$until.url + '/majorBaseInfo/getMajor?majorId=' + elementID).then(response => {
          //读取个例详细信息
          //数组？
          //this.updateProfessionForm.push(response.body.majorList);
          this.updateProfessionForm = response.body.majorList[0];
        }, response => {
          alert("找不到文件");
        });
      },
    }
  }
</script>
